package com.bolt.core.view.components;

import com.bolt.common.BoltConstants;
import com.bolt.common.lang.Assert;
import com.bolt.common.utils.StrUtil;

public class BindDataModel extends BindBaseModel {

    private Integer bindType;

    private String dbSourceId;

    private String dataSetId;

    private String dbTable;

    private String keyField;

    private String labelField;

    private String treeParentField = BoltConstants.DEFAULT_PARENT_FIELD;

    private boolean treeData = false;

    private boolean initData = false;


    private static final String SQL_TEMP = "select {},{} from {} ";

    public Integer getBindType() {
        return bindType;
    }

    public void setBindType(Integer bindType) {
        this.bindType = bindType;
    }

    public String getDbSourceId() {
        return dbSourceId;
    }

    public void setDbSourceId(String dbSourceId) {
        this.dbSourceId = dbSourceId;
    }

    public String getDbTable() {
        return dbTable;
    }

    public void setDbTable(String dbTable) {
        this.dbTable = dbTable;
    }

    public String getKeyField() {
        return keyField;
    }

    public void setKeyField(String keyField) {
        this.keyField = keyField;
    }

    public String getLabelField() {
        return labelField;
    }

    public void setLabelField(String labelField) {
        this.labelField = labelField;
    }

    public String getDataSetId() {
        return dataSetId;
    }

    public void setDataSetId(String dataSetId) {
        this.dataSetId = dataSetId;
    }

    public boolean isTreeData() {
        return treeData;
    }

    public void setTreeData(boolean treeData) {
        this.treeData = treeData;
    }

    public String getTreeParentField() {
        return treeParentField;
    }

    public void setTreeParentField(String treeParentField) {
        this.treeParentField = treeParentField;
    }


    public boolean isInitData() {
        return initData;
    }

    public void setInitData(boolean initData) {
        this.initData = initData;
    }

    public String toSql() {
        Assert.isNull(this.dbTable, "表名不能为空");
        Assert.isNull(this.keyField, "实际值字段名不为空");
        Assert.isNull(this.labelField, "显示值字段名不为空");
        return StrUtil.format(SQL_TEMP, this.keyField, this.labelField, this.dbTable);
    }
}